require(['grid', 'topBar', 'date', 'select2'], function () {
	$grid = $("#grid");
	
	//初始化顶部搜索栏
	function topBarInit() {
        $("#top").topBar({
            left: [
                {
                    type: 'filter-more',
                    dateType:'custom',
                    search: function () {
                        search();
                    },
                    item: [
                        {
                            text: '时间快捷',
                            name1: 'beginTime',
                            name2: 'endTime',
                            type: 'dateLine'
                        },
                        {
                            text: '操作类型',
                            name: 'qmnpltType',
                            width: '160',
                            type: 'select',
                            dict:'OLOG0000'
                        }
                    ]
                }
            ],
            right: [
                {
				    text: '查询',
				    type: 'btn',
//				    authority: '',
				    click: function () {
				    	search();
				    }
				},
				{
                    text: '导出',
                    type: 'export-btn',
                    authority: '',
                    item: [
                        {
                            text: 'Excel导出',
                            click: function () {
                                exportFile('Excel');
                            }
                        },
                        {
                            text: 'PDF导出',
                            click: function () {
                                exportFile('Pdf');
                            }
                        }
                    ]
                }
            ]
        });
    }
	
	$grid.grid({
		url : "/reportOperatDate/searchOperateLogStaticPage.htm",
		width:$(window).width() - 30,
		height:$(window).height()-131,
		sortorder: "desc",
		sortname: 'OPR_CNT',
		colModel:[
			{name:"mnpltType",index:"mnpltType",dict:"OLOG0000", label:'操作类型'},
			{name:"funcName",index:"funcName",width:"500", label:'操作功能'},
			{name:"oprCnt",index:"OPR_CNT",align:"right",sortable:true, label:'操作次数'},
			{name:"oprUserCnt",index:"OPR_USER_CNT",align:"right",sortable:true, label:'操作人数'},
			{name:"avgMnpltDura",index:"AVG_MNPLT_DURA",sortable:true, label:'平均响应时长'}
		],
		showPaper : true
	});
	
	function exportFile(suffix){
        if($('#grid').getGridParam("reccount")>0){
            var url = "/reportOperatDate/exportOperateLogStatic"+suffix+".htm";
            $.exportFile(url, $("#top").parent().getValues());
        }
        else{
            $.messager.alert("提示","请先查询数据。","info");
        }
    }
	
	function search(){
		if($("#top").parent().getValues().beginTime && $("#top").parent().getValues().endTime){
			$('#grid').grid('setGridParam', {
				page:1,
				datatype: "json",
				postData: $("#top").parent().getValues()
			}).trigger("reloadGrid");
		}else{
			$.messager.alert("提示","请先选择查询时间。","info");
		}
	}
	
	topBarInit();
	
	
	
});